***************************************************************
*******
* Replication code for "Income Inequality and Opinion Expression Gap in the American Public: An Analysis of Policy Priorities"
*******
* Journal of Public Policy
*******
* Published online: 2022
*******
* Authors: Tevfik Murat Yildirim and Alper T. Bulut
*******
* Dataset accessed: 2018 March
***************************************************************


* Replication data are available from the Roper Center for Public Opinion Research, and we are unable to share the data due to copyrights. 
* In order to access the data, one needs to be affiliated with institutional members of the Roper Center or request the data
* on a case-by-case basis by emailing data-services@ropercenter.org. See the study below for more information:

* Heffington, C., Park, B.B. and Williams, L.K., 2019. The “Most Important Problem” Dataset (MIPD): a new dataset on American 
* issue importance. Conflict Management and Peace Science, 36(3), pp.312-335.


* Time 
gen year=year(fw_end)
gen month=month(fw_end) 
 
* Generate DK answers
gen mis = (mip_cap1==.)

* Generate Partisan IDs
gen indep = (pid==1)
gen dem = (pid==0)
gen rep = (pid==2)

* Generate face2face interview method, and keep only open ended questions 
gen face2face= (interviewmethod==3)
drop if openended==0
drop if interviewmethod==4
gen pidmissing = (pid==.)



* Generate a variable that measures whether one identifies with the partisan affiliation of the sitting president
gen sameparty_w = 0
replace sameparty_w = 1 if party_id <-1 & dem==1
replace sameparty_w = 1 if party_id >1 & dem==0
replace sameparty_w = . if party_id ==.


************ Table 1: The Determinants of DK Responses to the MIP Question, 1960-2015 ************
* Model 1
logit mis i.income_quartile i.edulevel i.year
* Model 2
logit mis i.income_quartile i.edulevel white female sameparty_w age south urban i.year
**************************************************************************************************

************ Table 1: Simulated Predicted Probabilities ******************************************

* Note on variables: factor variables are not allowed in Clarify; use instead year dummies (those after 1960)

* Note on interpretation: calculate the relative changes using the baseline pr and first difference (mean) for each quartile
* In other words, divide the quantities of interest obtained from first differences by baseline pr to find the relative 
* changes in pr presented in Table 1.
tabulate year, generate(y)

estsimp logit mis income_quartile edulevel white female sameparty_w age south urban y22-y75
setx mean
simqi, prval(1)
simqi, fd(prval(1)) changex(income_quartile 1 2)
simqi, fd(prval(1)) changex(income_quartile 1 3)
simqi, fd(prval(1)) changex(income_quartile 1 4)


estsimp logit mis income_quartile edulevel white female sameparty_w age south urban y22-y75
setx mean
simqi, prval(1)
simqi, fd(prval(1)) changex(edulevel 1 2)
simqi, fd(prval(1)) changex(edulevel 1 3)
simqi, fd(prval(1)) changex(edulevel 1 4)
simqi, fd(prval(1)) changex(edulevel 1 5)


* Table 2: Interactive Effects of Education and Income Level
logit mis i.edulevel##c.income_quartile i.year 

logit mis i.edulevel##c.income_quartile female white sameparty_w age south urban i.year 



* Figure 2: The Effect of Income-Level on Policy Prioritization across Education Categories
logit mis i.edulevel##c.income_quartile female white sameparty_w age south urban i.year 
margins, at(edulevel=(1(1)5) income_quartile=(1(1)4)) level(90) 
marginsplot, title("") ytitle("Pr (Don't Know)") xtitle("") scheme(s1mono) recast(scatter) plot1opts(msymbol(Oh)) 



***** Multiple Imputation *****

* first, create individual topic categories (using the Singer coding scheme)

** SINGER
gen econ = (mip_singer1==1)
gen unemp = (mip_singer1==2)
gen inflat = (mip_singer1==3)
gen wage = (mip_singer1==5)
gen poverty_ineq = (mip_singer1==7)
gen socpolicy = (mip_singer1==9)
gen welf = (mip_singer1==10)
gen edupol = (mip_singer1==11)
gen healthpol = (mip_singer1==12)
gen oldage = (mip_singer1==13)
gen housing = (mip_singer1==15)
gen civillib = (mip_singer1==18)
gen youth = (mip_singer1==19)
gen defense_spending = (mip_singer1==20)
gen terrorism = (mip_singer1==21)
gen tax = (mip_singer1==70)
drop crime
gen crime = (mip_singer1==40)
gen corruption = (mip_singer1==31)
gen foreign = (mip_singer1==27)
gen budget = (mip_singer1==30)
gen war = (mip_singer1==22)
gen trust = (mip_singer1==33)
gen immigration = (mip_singer1==50)


** Create 'missing' versions of some of salient Singer policy categories
replace poverty_ineq = . if mip_singer1==.
replace socpolicy = . if mip_singer1==.
replace wage = . if mip_singer1==.
replace unemp = . if mip_singer1==.
replace unemp = . if mip_singer1==.
replace foreign = . if mip_singer1==.
replace edupol = . if mip_singer1==.
replace housing = . if mip_singer1==.
replace healthpol = . if mip_singer1==.
replace welf = . if mip_singer1==.
replace crime = . if mip_singer1==.
replace civillib = . if mip_singer1==.



****** Multiple Imputation

* run the code below for each policy area (civil liberties, crime, welfare, health policy, education policy) separately
* after imputing the data for a policy area, restore the original dataset to repeat the process for other policy categories



* welfare

*the original model
logit welf i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73
* imputed model
mi set mlong
mi register imputed welf
mi register regular income_quartile edulevel white female sameparty_w age south urban y25-y73
mi impute reg welf income_quartile edulevel white female sameparty_w age south urban y25-y73, add(10) force rseed(2232)
mi estimate: logit welf i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73

qui mi xeq: generate byte mis_welf = missing(welf)
mi register regular mis_welf
mi xeq 1/5: summarize welf if mis_welf==0; summarize welf if mis_welf==1; summarize welf



* crime

* original model
logit crime i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73

* imputed model
mi set mlong
mi register imputed crime
mi register regular income_quartile edulevel white female sameparty_w age south urban y25-y73
mi impute reg crime income_quartile edulevel white female sameparty_w age south urban y25-y73, add(10) force rseed(2232)
mi estimate: logit crime i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73

qui mi xeq: generate byte mis_crime = missing(crime)
mi register regular mis_crime
mi xeq 1/5: summarize crime if mis_crime==0; summarize crime if mis_crime==1; summarize crime

* Civil liberties

* original model
logit civillib i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73

* imputed model
mi set mlong
mi register imputed civillib
mi register regular income_quartile edulevel white female sameparty_w age south urban y25-y73
mi impute reg civillib income_quartile edulevel white female sameparty_w age south urban y25-y73, add(10) force rseed(2232)
mi estimate: logit civillib i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73

qui mi xeq: generate byte mis_civillib = missing(civillib)
mi register regular mis_civillib
mi xeq 1/5: summarize civillib if mis_civillib==0; summarize civillib if mis_civillib==1; summarize civillib



* Health policy 

* original model
logit healthpol i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73

* imputed model
mi set mlong
mi register imputed healthpol
mi register regular income_quartile edulevel white female sameparty_w age south urban y25-y73
mi impute reg healthpol income_quartile edulevel white female sameparty_w age south urban y25-y73, add(10) force rseed(2232)
mi estimate: logit healthpol i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73

qui mi xeq: generate byte mis_healthpol = missing(healthpol)
mi register regular mis_healthpol
mi xeq 1/5: summarize healthpol if mis_healthpol==0; summarize healthpol if mis_healthpol==1; summarize healthpol



* Education policy 

* original model
logit edupol i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73

* imputed model
mi set mlong
mi register imputed edupol
mi register regular income_quartile edulevel white female sameparty_w age south urban y25-y73
mi impute reg edupol income_quartile edulevel white female sameparty_w age south urban y25-y73, add(10) force rseed(2232)
mi estimate: logit edupol i.income_quartile i.edulevel white female sameparty_w age south urban y25-y73

qui mi xeq: generate byte mis_edupol = missing(edupol)
mi register regular mis_edupol
mi xeq 1/5: summarize edupol if mis_edupol==0; summarize edupol if mis_edupol==1; summarize edupol



****************************************************
** Additional models for the Supplementary File: control for addition variables including attention to politics and presidential approval
logit mis income_quartile edulevel white female sameparty_w age south urban i.studyno

logit mis approve income_quartile edulevel white female sameparty_w age south urban i.year

logit mis att income_quartile edulevel white female sameparty_w age south urban i.year

logit mis religiosity income_quartile edulevel white female sameparty_w age south urban i.year





******* Additional analyses using survey weights based on Census data
* Prepare the Census Data for merging

*** Generate a "decade" variable
gen decade = year(fw_end)
recode decade (1940/1949=1940) (1950/1959=1950) (1960/1969=1960) (1970/1979=1970) (1980/1989=1980) (1990/1999=1990) (2000/2009=2000) (2010/2019=2010) (2020/2029=2020)

*** Generate the age bands variable
gen agebands = age
recode agebands (min/34=1) (35/54=2) (55/max=3)

*** Merge in the population proportions
sort decade agebands male white edulevel
merge m:1 decade agebands male white edulevel using "/Volumes/TMY Elements/Census data for BJPS/CPS/weight_amwe2.dta"
tab _merge 
drop if _merge == 2
drop _merge

sort decade agebands male white




* Re-run the models with survey weights 
* Model 1
logit mis i.income_quartile i.edulevel i.year [pw=pop_amwe]
* Model 2
logit mis i.income_quartile i.edulevel white female sameparty_w age south urban i.year [pw=pop_amwe]

